using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace ICP_MS.Plugin.Experiment;

public class FormBlankCalibration : Form
{
	private ExperimentDatas experiment = null;

	private ExperimentDB db = null;

	private IContainer components = null;

	private GroupBox groupBox1;

	private TextBox txtB1;

	private Label label2;

	private TextBox txtK1;

	private Label label1;

	private GroupBox groupBox2;

	private TextBox txtB2;

	private Label label3;

	private TextBox txtK2;

	private Label label4;

	private GroupBox groupBox3;

	private TextBox txtB3;

	private Label label5;

	private TextBox txtK3;

	private Label label6;

	private GroupBox groupBox4;

	private TextBox txtB4;

	private Label label7;

	private TextBox txtK4;

	private Label label8;

	private GroupBox groupBox5;

	private TextBox txtB5;

	private Label label9;

	private TextBox txtK5;

	private Label label10;

	private Button btnOK;

	private Button btnCancel;

	public FormBlankCalibration()
	{
		InitializeComponent();
	}

	public void SetParams(ExperimentDatas experiment, ExperimentDB db)
	{
		this.experiment = experiment;
		this.db = db;
	}

	private void FormBlankCalibration_Load(object sender, EventArgs e)
	{
		foreach (BlankCalibration blankcali in experiment.BlankCalibration)
		{
			switch (blankcali.Symbol)
			{
			case "5Bkg":
				txtK1.Text = blankcali.Slope.ToString();
				txtB1.Text = blankcali.Intercept.ToString();
				break;
			case "8Bkg":
				txtK2.Text = blankcali.Slope.ToString();
				txtB2.Text = blankcali.Intercept.ToString();
				break;
			case "101Bkg":
				txtK3.Text = blankcali.Slope.ToString();
				txtB3.Text = blankcali.Intercept.ToString();
				break;
			case "220Bkg":
				txtK4.Text = blankcali.Slope.ToString();
				txtB4.Text = blankcali.Intercept.ToString();
				break;
			case "245Bkg":
				txtK5.Text = blankcali.Slope.ToString();
				txtB5.Text = blankcali.Intercept.ToString();
				break;
			}
		}
	}

	private void btnCancel_Click(object sender, EventArgs e)
	{
		Close();
	}

	private void btnOK_Click(object sender, EventArgs e)
	{
		try
		{
			BlankCalibration blankcali = experiment.BlankCalibration.Find((BlankCalibration r) => r.Symbol == "5Bkg");
			blankcali.Slope = Convert.ToDouble(txtK1.Text);
			blankcali.Intercept = Convert.ToDouble(txtB1.Text);
			blankcali = experiment.BlankCalibration.Find((BlankCalibration r) => r.Symbol == "8Bkg");
			blankcali.Slope = Convert.ToDouble(txtK2.Text);
			blankcali.Intercept = Convert.ToDouble(txtB2.Text);
			blankcali = experiment.BlankCalibration.Find((BlankCalibration r) => r.Symbol == "101Bkg");
			blankcali.Slope = Convert.ToDouble(txtK3.Text);
			blankcali.Intercept = Convert.ToDouble(txtB3.Text);
			blankcali = experiment.BlankCalibration.Find((BlankCalibration r) => r.Symbol == "220Bkg");
			blankcali.Slope = Convert.ToDouble(txtK4.Text);
			blankcali.Intercept = Convert.ToDouble(txtB4.Text);
			blankcali = experiment.BlankCalibration.Find((BlankCalibration r) => r.Symbol == "245Bkg");
			blankcali.Slope = Convert.ToDouble(txtK5.Text);
			blankcali.Intercept = Convert.ToDouble(txtB5.Text);
			if (MessageBox.Show("是否应用到初始值", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
			{
				XMLFile.Save(Application.StartupPath + "//iMassConfig//BlankCalibration.xml", experiment.BlankCalibration);
			}
			experiment.Dirty.BlankCalibrationDirty = true;
			MessageBox.Show("设置成功");
			base.DialogResult = DialogResult.OK;
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.groupBox1 = new System.Windows.Forms.GroupBox();
		this.txtK1 = new System.Windows.Forms.TextBox();
		this.label1 = new System.Windows.Forms.Label();
		this.txtB1 = new System.Windows.Forms.TextBox();
		this.label2 = new System.Windows.Forms.Label();
		this.groupBox2 = new System.Windows.Forms.GroupBox();
		this.txtB2 = new System.Windows.Forms.TextBox();
		this.label3 = new System.Windows.Forms.Label();
		this.txtK2 = new System.Windows.Forms.TextBox();
		this.label4 = new System.Windows.Forms.Label();
		this.groupBox3 = new System.Windows.Forms.GroupBox();
		this.txtB3 = new System.Windows.Forms.TextBox();
		this.label5 = new System.Windows.Forms.Label();
		this.txtK3 = new System.Windows.Forms.TextBox();
		this.label6 = new System.Windows.Forms.Label();
		this.groupBox4 = new System.Windows.Forms.GroupBox();
		this.txtB4 = new System.Windows.Forms.TextBox();
		this.label7 = new System.Windows.Forms.Label();
		this.txtK4 = new System.Windows.Forms.TextBox();
		this.label8 = new System.Windows.Forms.Label();
		this.groupBox5 = new System.Windows.Forms.GroupBox();
		this.txtB5 = new System.Windows.Forms.TextBox();
		this.label9 = new System.Windows.Forms.Label();
		this.txtK5 = new System.Windows.Forms.TextBox();
		this.label10 = new System.Windows.Forms.Label();
		this.btnOK = new System.Windows.Forms.Button();
		this.btnCancel = new System.Windows.Forms.Button();
		this.groupBox1.SuspendLayout();
		this.groupBox2.SuspendLayout();
		this.groupBox3.SuspendLayout();
		this.groupBox4.SuspendLayout();
		this.groupBox5.SuspendLayout();
		base.SuspendLayout();
		this.groupBox1.Controls.Add(this.txtB1);
		this.groupBox1.Controls.Add(this.label2);
		this.groupBox1.Controls.Add(this.txtK1);
		this.groupBox1.Controls.Add(this.label1);
		this.groupBox1.Location = new System.Drawing.Point(21, 22);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(361, 76);
		this.groupBox1.TabIndex = 0;
		this.groupBox1.TabStop = false;
		this.groupBox1.Text = "5Bkg";
		this.txtK1.Location = new System.Drawing.Point(78, 33);
		this.txtK1.Name = "txtK1";
		this.txtK1.Size = new System.Drawing.Size(79, 20);
		this.txtK1.TabIndex = 3;
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(45, 33);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(27, 15);
		this.label1.TabIndex = 2;
		this.label1.Text = "K：";
		this.txtB1.Location = new System.Drawing.Point(237, 33);
		this.txtB1.Name = "txtB1";
		this.txtB1.Size = new System.Drawing.Size(79, 20);
		this.txtB1.TabIndex = 5;
		this.label2.AutoSize = true;
		this.label2.Location = new System.Drawing.Point(204, 33);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(26, 15);
		this.label2.TabIndex = 4;
		this.label2.Text = "b：";
		this.groupBox2.Controls.Add(this.txtB2);
		this.groupBox2.Controls.Add(this.label3);
		this.groupBox2.Controls.Add(this.txtK2);
		this.groupBox2.Controls.Add(this.label4);
		this.groupBox2.Location = new System.Drawing.Point(21, 121);
		this.groupBox2.Name = "groupBox2";
		this.groupBox2.Size = new System.Drawing.Size(361, 76);
		this.groupBox2.TabIndex = 0;
		this.groupBox2.TabStop = false;
		this.groupBox2.Text = "8Bkg";
		this.txtB2.Location = new System.Drawing.Point(237, 33);
		this.txtB2.Name = "txtB2";
		this.txtB2.Size = new System.Drawing.Size(79, 20);
		this.txtB2.TabIndex = 5;
		this.label3.AutoSize = true;
		this.label3.Location = new System.Drawing.Point(204, 33);
		this.label3.Name = "label3";
		this.label3.Size = new System.Drawing.Size(26, 15);
		this.label3.TabIndex = 4;
		this.label3.Text = "b：";
		this.txtK2.Location = new System.Drawing.Point(78, 33);
		this.txtK2.Name = "txtK2";
		this.txtK2.Size = new System.Drawing.Size(79, 20);
		this.txtK2.TabIndex = 3;
		this.label4.AutoSize = true;
		this.label4.Location = new System.Drawing.Point(45, 33);
		this.label4.Name = "label4";
		this.label4.Size = new System.Drawing.Size(27, 15);
		this.label4.TabIndex = 2;
		this.label4.Text = "K：";
		this.groupBox3.Controls.Add(this.txtB3);
		this.groupBox3.Controls.Add(this.label5);
		this.groupBox3.Controls.Add(this.txtK3);
		this.groupBox3.Controls.Add(this.label6);
		this.groupBox3.Location = new System.Drawing.Point(21, 218);
		this.groupBox3.Name = "groupBox3";
		this.groupBox3.Size = new System.Drawing.Size(361, 76);
		this.groupBox3.TabIndex = 0;
		this.groupBox3.TabStop = false;
		this.groupBox3.Text = "101Bkg";
		this.txtB3.Location = new System.Drawing.Point(237, 33);
		this.txtB3.Name = "txtB3";
		this.txtB3.Size = new System.Drawing.Size(79, 20);
		this.txtB3.TabIndex = 5;
		this.label5.AutoSize = true;
		this.label5.Location = new System.Drawing.Point(204, 33);
		this.label5.Name = "label5";
		this.label5.Size = new System.Drawing.Size(26, 15);
		this.label5.TabIndex = 4;
		this.label5.Text = "b：";
		this.txtK3.Location = new System.Drawing.Point(78, 33);
		this.txtK3.Name = "txtK3";
		this.txtK3.Size = new System.Drawing.Size(79, 20);
		this.txtK3.TabIndex = 3;
		this.label6.AutoSize = true;
		this.label6.Location = new System.Drawing.Point(45, 33);
		this.label6.Name = "label6";
		this.label6.Size = new System.Drawing.Size(27, 15);
		this.label6.TabIndex = 2;
		this.label6.Text = "K：";
		this.groupBox4.Controls.Add(this.txtB4);
		this.groupBox4.Controls.Add(this.label7);
		this.groupBox4.Controls.Add(this.txtK4);
		this.groupBox4.Controls.Add(this.label8);
		this.groupBox4.Location = new System.Drawing.Point(21, 313);
		this.groupBox4.Name = "groupBox4";
		this.groupBox4.Size = new System.Drawing.Size(361, 76);
		this.groupBox4.TabIndex = 0;
		this.groupBox4.TabStop = false;
		this.groupBox4.Text = "220Bkg";
		this.txtB4.Location = new System.Drawing.Point(237, 33);
		this.txtB4.Name = "txtB4";
		this.txtB4.Size = new System.Drawing.Size(79, 20);
		this.txtB4.TabIndex = 5;
		this.label7.AutoSize = true;
		this.label7.Location = new System.Drawing.Point(204, 33);
		this.label7.Name = "label7";
		this.label7.Size = new System.Drawing.Size(26, 15);
		this.label7.TabIndex = 4;
		this.label7.Text = "b：";
		this.txtK4.Location = new System.Drawing.Point(78, 33);
		this.txtK4.Name = "txtK4";
		this.txtK4.Size = new System.Drawing.Size(79, 20);
		this.txtK4.TabIndex = 3;
		this.label8.AutoSize = true;
		this.label8.Location = new System.Drawing.Point(45, 33);
		this.label8.Name = "label8";
		this.label8.Size = new System.Drawing.Size(27, 15);
		this.label8.TabIndex = 2;
		this.label8.Text = "K：";
		this.groupBox5.Controls.Add(this.txtB5);
		this.groupBox5.Controls.Add(this.label9);
		this.groupBox5.Controls.Add(this.txtK5);
		this.groupBox5.Controls.Add(this.label10);
		this.groupBox5.Location = new System.Drawing.Point(21, 409);
		this.groupBox5.Name = "groupBox5";
		this.groupBox5.Size = new System.Drawing.Size(361, 76);
		this.groupBox5.TabIndex = 0;
		this.groupBox5.TabStop = false;
		this.groupBox5.Text = "245Bkg";
		this.txtB5.Location = new System.Drawing.Point(237, 33);
		this.txtB5.Name = "txtB5";
		this.txtB5.Size = new System.Drawing.Size(79, 20);
		this.txtB5.TabIndex = 5;
		this.label9.AutoSize = true;
		this.label9.Location = new System.Drawing.Point(204, 33);
		this.label9.Name = "label9";
		this.label9.Size = new System.Drawing.Size(26, 15);
		this.label9.TabIndex = 4;
		this.label9.Text = "b：";
		this.txtK5.Location = new System.Drawing.Point(78, 33);
		this.txtK5.Name = "txtK5";
		this.txtK5.Size = new System.Drawing.Size(79, 20);
		this.txtK5.TabIndex = 3;
		this.label10.AutoSize = true;
		this.label10.Location = new System.Drawing.Point(45, 33);
		this.label10.Name = "label10";
		this.label10.Size = new System.Drawing.Size(27, 15);
		this.label10.TabIndex = 2;
		this.label10.Text = "K：";
		this.btnOK.Location = new System.Drawing.Point(420, 178);
		this.btnOK.Name = "btnOK";
		this.btnOK.Size = new System.Drawing.Size(99, 40);
		this.btnOK.TabIndex = 1;
		this.btnOK.Text = "确定";
		this.btnOK.UseVisualStyleBackColor = true;
		this.btnOK.Click += new System.EventHandler(btnOK_Click);
		this.btnCancel.Location = new System.Drawing.Point(420, 240);
		this.btnCancel.Name = "btnCancel";
		this.btnCancel.Size = new System.Drawing.Size(99, 40);
		this.btnCancel.TabIndex = 1;
		this.btnCancel.Text = "取消";
		this.btnCancel.UseVisualStyleBackColor = true;
		this.btnCancel.Click += new System.EventHandler(btnCancel_Click);
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(597, 515);
		base.Controls.Add(this.btnCancel);
		base.Controls.Add(this.btnOK);
		base.Controls.Add(this.groupBox5);
		base.Controls.Add(this.groupBox4);
		base.Controls.Add(this.groupBox3);
		base.Controls.Add(this.groupBox2);
		base.Controls.Add(this.groupBox1);
		base.Name = "FormBlankCalibration";
		this.Text = "背景校正";
		base.Load += new System.EventHandler(FormBlankCalibration_Load);
		this.groupBox1.ResumeLayout(false);
		this.groupBox1.PerformLayout();
		this.groupBox2.ResumeLayout(false);
		this.groupBox2.PerformLayout();
		this.groupBox3.ResumeLayout(false);
		this.groupBox3.PerformLayout();
		this.groupBox4.ResumeLayout(false);
		this.groupBox4.PerformLayout();
		this.groupBox5.ResumeLayout(false);
		this.groupBox5.PerformLayout();
		base.ResumeLayout(false);
	}
}
